﻿using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using DemountCIM.View;
using DemountCIM.Framework.DataBase.Table;
using DemountCIM.Framework.SECSGEM;

namespace DemountCIM
{
    public class MainWindowModel : BindableBase
    {
        // 初始化属性
        private List<Naviagtion> pageList;
        private UserInfo userInfo;

        // 未初始化
        private ContentControl nowPage;
        private string commState;                               // 通讯状态
        private string controlState;                            // 控制状态


        public MainWindowModel(List<Naviagtion> naviagtions)
        {
            pageList = naviagtions;
            userInfo = new UserInfo();

        }

        #region MES相关

        public string CommState
        {
            get { return commState; }
            set
            {
                SetProperty(ref commState, value);
            }
        }

        public string ControlState
        {
            get { return controlState; }
            set
            {
                SetProperty(ref controlState, value);
            }
        }

        internal void SetCommState(_eCommState commState)
        {
            string tempContent = "";
            switch (commState)
            {
                case _eCommState.Comm_None:
                    tempContent = "Unknown State";
                    break;
                case _eCommState.Comm_Disabled:
                    tempContent = "Disabled";
                    break;
                case _eCommState.Comm_WaitCRFromHost:
                    tempContent = "WaitCRFromHost";
                    break;
                case _eCommState.Comm_WaitDelay:
                    tempContent = "WaitDelay";
                    break;
                case _eCommState.Comm_WaitCRA:
                    tempContent = "WaitCRA";
                    break;
                case _eCommState.Comm_Communicating:
                    tempContent = "Communicating";
                    break;
            }
            CommState = tempContent;
        }

        internal void SetControlState(_eControlState state)
        {
            string tempContent = "";
            switch (state)
            {
                case _eControlState.Control_None:
                    tempContent = "Unknown State";
                    break;
                case _eControlState.Control_EqOffline:
                    tempContent = "EqOffline";
                    break;
                case _eControlState.Control_AttemptOnline:
                    tempContent = "AttemptOnline";
                    break;
                case _eControlState.Control_HostOffline:
                    tempContent = "HostOffline";
                    break;
                case _eControlState.Control_Local:
                    tempContent = "Local";
                    break;
                case _eControlState.Control_Remote:
                    tempContent = "Remote";
                    break;
            }
            controlState = tempContent;
        }

        #endregion

        #region 用户

        public UserInfo User
        {
            get { return userInfo; }
            set
            {
                SetProperty(ref userInfo, value);
            }
        }

        public class UserInfo : BindableBase
        {
            private string userName;
            private string userLevel;
            private string loginState;

            public UserInfo()
            {
                Clear();
            }

            public string UserName
            {
                get { return userName; }
                set
                {
                    SetProperty(ref userName, value);
                }
            }

            public string UserLevel
            {
                get { return userLevel; }
                set
                {
                    SetProperty(ref userLevel, value);
                }
            }

            public string LoginState
            {
                get { return loginState; }
                set
                {
                    SetProperty(ref loginState, value);
                }
            }

            public void Clear()
            {
                UserName = "无效";
                UserLevel = "无权限";
                LoginState = "未登录";
            }
        }

        #endregion

        #region 侧边导航栏

        public List<Naviagtion> PageList
        {
            get { return pageList; }
            set { SetProperty(ref pageList, value); }
        }

        public ContentControl NowPage
        {
            get { return nowPage; }
            set { SetProperty(ref nowPage, value); }
        }

        public class Naviagtion : BindableBase
        {
            private int id;
            private string title;
            private ContentControl content;
            private Geometry icon;

            public Naviagtion(int id, string title, ContentControl content, Geometry icon)
            {
                this.id = id;
                this.title = title;
                this.content = content;
                this.icon = icon;
            }
            public int Id { get { return id; } set { SetProperty(ref id, value); } }

            public string Title { get { return title; } set { SetProperty(ref title, value); } }

            public Geometry Icon { get { return icon; } set { SetProperty(ref icon, value); } }

            public ContentControl Content { get { return content; } set { SetProperty(ref content, value); } }
        }

        #endregion

    }
}
